package com.example.smartcampus;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class Mydata extends SQLiteOpenHelper {



    public SQLiteDatabase getReadableDatabase() {
        return super.getReadableDatabase();
    }

    // 或者在需要写入的地方使用
    public SQLiteDatabase getWritableDatabase() {
        return super.getWritableDatabase();
    }

    public Mydata(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
//        建表
        sqLiteDatabase.execSQL("create table information(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "name text, " +
                "sex text," +
                "birthday text," +
                "user text," +
                "password text);");
//        初始化数据
        sqLiteDatabase.execSQL("insert into information(name,sex,birthday,user,password) values('侯云龙','男','2004-1-1','root','123456')");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        sqLiteDatabase.execSQL("drop table if exists information");
        onCreate(sqLiteDatabase);
    }
}
